# 用户信息列表
users = [{'name': 'mia', 'phone': '213', 'qq': '3546', 'email': '123'},
         {'name': 'jack', 'phone': '124235', 'qq': '23423434', 'email': '3465'},
         {'name': 'tom', 'phone': '234', 'qq': '234', 'email': '09877'}]


def menu():
    print('''欢迎来到名片管理系统
    1、新建名片
    2、查询名片
    3、删除名片
    0、退出系统
    ''')


# 新增
def adduser(name, phone, qq, mail):
    user = {
        "name": name,
        "phone": phone,
        "qq": qq,
        "mail": mail,
    }
    users.append(user)
    return True


# 删除
def deluser(name):
    for i, u in enumerate(users):
        if u['name'] == name:
            users.pop(i)
            print("用户删除成功！")
            print("=" * 10)
            break
    else:
        print("需要没有的名片不存在")


# 查询
def getuser(name):
    if not name:
        for u in users:
            print("姓名：", u['name'])
            print("电话：", u['phone'])
            print("QQ：", u['qq'])
            print("邮箱：", u['mail'])
            print("=" * 10)
    else:
        for i, u in enumerate(users):
            if u['name'] == name:
                print("姓名：", u['name'])
                print("电话：", u['phone'])
                print("QQ：", u['qq'])
                print("邮箱：", u['mail'])
                print("=" * 10)
                break
        else:
            print("未查询到信息")


# 退出
def quit():
    print("欢迎下次使用名片管理系统")


menu()

while True:
    mId = int(input("请输入菜单的操作序号："))
    if mId == 1:
        name = input("姓名：")
        phone = input("电话：")
        qq = input("QQ：")
        mail = input("邮箱：")
        result = adduser(name, phone, qq, mail)
        if result:
            print("用户新增成功！")
            print("=" * 10)
        else:
            print("请重试！")
    elif mId == 2:
        name = input("输入查询卡片的名称：")
        getuser(name)
    elif mId == 3:
        name = input("请输入需要删除的姓名：")
        deluser(name)
    elif mId == 0:
        quit()
        break
    else:
        print("请重试")
